<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="${ctx}/static/lib/layui/css/layui.css">
<style type="text/css">
	.main_div{
		margin : 15px;
	}
</style>
</head>
<body>
  	<div class="main_div">
		<form id="form_add" class="layui-form layui-form-pane" action="">
		  <div class="layui-form-item">
		    <label class="layui-form-label">机会来源</label>
		    <div class="layui-input-block">
		      <input type="text" name="chanceSource" autocomplete="off" placeholder="请输入标题" class="layui-input">
		    </div>
		  </div>
		   <div class="layui-form-item">
			    <label class="layui-form-label">所属客户</label>
			    <div class="layui-input-block">
			      <select name="customerId" id="customerId"  lay-verify="required">
			      </select>
			    </div>
			  </div>
		      <div class="layui-form-item">
			    <label class="layui-form-label">看重产品</label>
			    <div class="layui-input-block">
			      <select name="productId" id="productId"  lay-verify="required">
			      </select>
			    </div>
			  </div>
		   <div class="layui-form-item">
			    <label class="layui-form-label">指派营销人员</label>
			    <div class="layui-input-block">
			      <select name="userId" id="userId" lay-verify="required">
			      </select>
			    </div>
			  </div>
		   <div class="layui-form-item">
		    <label class="layui-form-label">成功几率</label>
		    <div class="layui-input-block">
		      <input type="text" name="successRate" autocomplete="off" placeholder="请输入标题" class="layui-input">
		    </div>
		  </div>
		    <div class="layui-form-item">
		    <label class="layui-form-label">机会描述</label>
		    <div class="layui-input-block">
		      <input type="text" name="description" autocomplete="off" placeholder="请输入标题" class="layui-input">
		    </div>
		  </div>
		   <div class="layui-form-item">
		    <label class="layui-form-label">创建人</label>
		    <div class="layui-input-block">
		      <input type="text" name="createMan" autocomplete="off" value="${user.name}" class="layui-input">
		    </div>
		  </div>
		   <div class="layui-form-item">
			    <label class="layui-form-label">分配状态</label>
			    <div class="layui-input-block">
			      <select name="status"  lay-verify="required">
			        <option value="">未开发</option>
			        <option value="0">未分配</option>
			        <option value="1">已分配</option>
			      </select>
			    </div>
			  </div>
		   <div class="layui-form-item">
			    <label class="layui-form-label">选择开发状态</label>
			    <div class="layui-input-block">
			      <select name="devResult" lay-verify="required">
			        <option value="">未开发</option>
			        <option value="0">未开发</option>
			        <option value="1">开发中</option>
			        <option value="2">开发成功</option>
			        <option value="3">开发失败</option>
			      </select>
			    </div>
			  </div>
		  
		  
		</form>
		<input type="button" class="layui-btn" onclick="submitForm()" value="添加"></input>
	</div>


	<script src="${ctx}/static/back/js/jquery.js"></script>
	<script src="${ctx}/static/commom/mylayer.js"></script>
	<script src="${ctx}/static/commom/util.js"></script>
	<script src="${ctx}/static/lib/layui/layui.js"></script>
	<script src="${ctx}/static/lib/kindeditor/kindeditor.js"></script>
	<script src="${ctx}/static/lib/kindeditor/lang/zh_CN.js"></script>
	<script>
	
	function submitForm(){
		$.ajax({
			url : '${ctx}/salechance/insert.action',
			data : $('#form_add').serialize(),
			type : 'POST',
			dataType : 'json',
			success : function(resp) {
				if(resp.code == util.SUCCESS) {
					//mylayer.success(jsonObj.msg);
					mylayer.confirm("添加成功，是够跳转到营销列表界面？", "${ctx}/salechance/tosalechancepage.action");
				} else {
					mylayer.errorMsg(resp.msg);
				}
			}
		});
	}
	
	layui.config({
	    base : '${ctx}/static/lib/'
	  }).extend({
	    selectM: './layui_extends/selectM'
	  }).use(['form','upload','selectM'],function(){
	  	var form = layui.form;
	  	var upload = layui.upload;
	  	var selectM = layui.selectM;
		
		//ajax方式提交form表单
	
		
	 	$.ajax({
	 		url : '${ctx}/permission/selectAllpermissions.action',
			type : 'POST',
			dataType : 'json',
			success : function(resp) {
				if(resp.code == util.SUCCESS) {
					mylayer.success(resp.msg);
					 //多选标签-基本配置
				    var tagIns = selectM({
				      //元素容器【必填】
				      elem: '#permissions'
				      //候选数据【必填】
				      ,data: resp.data
				      //默认值
				      /* ,selected: [1,2] */
				      // 默认最多选中5个
				      ,max : 100
				    });
				} else {
					mylayer.errorMsg(resp.msg);
				}
			}
		});
	
		
		var myKindEditor ;
        KindEditor.ready(function(K) {
            var kingEditorParams = {
                 //指定上传文件参数名称
                 filePostName  : "file",
                 //指定上传文件请求的url。
                 uploadJson : '${ctx}/upload/uploadImgByEditor.action',
                 //上传类型，分别为image、flash、media、file
                 dir : "image",
                 afterBlur: function () { this.sync(); }
           }
           var editor = K.editor(kingEditorParams);
           
          //富文本编辑器
          myKindEditor = KindEditor.create('#form_add[name=detail]', kingEditorParams);
        });
	  });
	
	
	$(function(){
		$.ajax({
			url : "${ctx}/customer/selectIds.action",
			type : "post",
			dataTyper : "json",
			success : function(resp){
				console.log(resp);
				if (resp.code == util.SUCCESS) {
					var html = "<option value=''>请选择一级分类</option>";
					var data = resp.data;
					for(var i = 0;i < data.length;i++){
						html += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
					}
					$("#customerId").html(html);
				}
			}
		})
	})
	
	
	$(function(){
		$.ajax({
			url : "${ctx}/product/selectIds.action",
			type : "post",
			dataTyper : "json",
			success : function(resp){
				console.log(resp);
				if (resp.code == util.SUCCESS) {
					var html = "<option value=''>请选择商品</option>";
					var data = resp.data;
					for(var i = 0;i < data.length;i++){
						html += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
					}
					$("#productId").html(html);
				}
			}
		})
	})
	
	
	$(function(){
		$.ajax({
			url : "${ctx}/user/selectIds.action",
			type : "post",
			dataTyper : "json",
			success : function(resp){
				console.log(resp);
				if (resp.code == util.SUCCESS) {
					var html = "<option value=''>请选择营销人员</option>";
					var data = resp.data;
					for(var i = 0;i < data.length;i++){
						html += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
					}
					$("#userId").html(html);
				}
			}
		})
	})
	
	
	</script>
</body>
</html>
